﻿#pragma once
#include "FlatForm.h"
#include "APIUtils.h"
#include "AsyncHttpUtils.h"
#include "CryptUtils.h"
namespace rjksClient {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace Newtonsoft::Json::Linq;

	/// <summary>
	/// Form1 摘要
	/// </summary>
public ref class frmLogin : public FlatForm
	{
	
	private: System::Windows::Forms::Button^  btnResetPwd;
	private: System::Windows::Forms::Button^  btnClear;

	private: System::Windows::Forms::TextBox^  txtBox1;
	private: System::Windows::Forms::TextBox^  txtBox2;


	private: System::Windows::Forms::Button^  btnLogin;
	public:
		Action<String^>^ LoginCallback;
		Action<String^>^ ResetPwdCallback;
	private: System::Windows::Forms::Button^  btnConfig;


	public: 

	public: 

	public: 
	private: System::Windows::Forms::TextBox^  textBox1;

	public:
		frmLogin::frmLogin(void)
		{
			InitializeComponent();
			//
			//TODO: 在此处添加构造函数代码
			//
			MaxMinConfig=MAXMIN_NONE;
		}
	protected:
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		~frmLogin()
		{
			if (components)
			{
				delete components;
			}
		}

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要
		/// 使用代码编辑器修改此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(frmLogin::typeid));
			this->btnLogin = (gcnew System::Windows::Forms::Button());
			this->btnResetPwd = (gcnew System::Windows::Forms::Button());
			this->btnClear = (gcnew System::Windows::Forms::Button());
			this->txtBox1 = (gcnew System::Windows::Forms::TextBox());
			this->txtBox2 = (gcnew System::Windows::Forms::TextBox());
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->btnConfig = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// btnLogin
			// 
			this->btnLogin->Anchor = System::Windows::Forms::AnchorStyles::Top;
			this->btnLogin->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(41)), static_cast<System::Int32>(static_cast<System::Byte>(128)), 
				static_cast<System::Int32>(static_cast<System::Byte>(185)));
			this->btnLogin->FlatAppearance->BorderSize = 0;
			this->btnLogin->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
			this->btnLogin->Font = (gcnew System::Drawing::Font(L"微软雅黑", 16.2F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->btnLogin->ForeColor = System::Drawing::Color::White;
			this->btnLogin->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"btnLogin.Image")));
			this->btnLogin->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;
			this->btnLogin->Location = System::Drawing::Point(347, 38);
			this->btnLogin->Margin = System::Windows::Forms::Padding(6, 7, 6, 7);
			this->btnLogin->Name = L"btnLogin";
			this->btnLogin->Size = System::Drawing::Size(200, 65);
			this->btnLogin->TabIndex = 2;
			this->btnLogin->Text = L"登录";
			this->btnLogin->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
			this->btnLogin->UseVisualStyleBackColor = false;
			this->btnLogin->Click += gcnew System::EventHandler(this, &frmLogin::btnLogin_Click);
			// 
			// btnResetPwd
			// 
			this->btnResetPwd->Anchor = System::Windows::Forms::AnchorStyles::Top;
			this->btnResetPwd->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(127)), static_cast<System::Int32>(static_cast<System::Byte>(140)), 
				static_cast<System::Int32>(static_cast<System::Byte>(141)));
			this->btnResetPwd->FlatAppearance->BorderSize = 0;
			this->btnResetPwd->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
			this->btnResetPwd->Font = (gcnew System::Drawing::Font(L"微软雅黑", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->btnResetPwd->ForeColor = System::Drawing::Color::White;
			this->btnResetPwd->Location = System::Drawing::Point(404, 112);
			this->btnResetPwd->Margin = System::Windows::Forms::Padding(6, 7, 6, 7);
			this->btnResetPwd->Name = L"btnResetPwd";
			this->btnResetPwd->Size = System::Drawing::Size(81, 40);
			this->btnResetPwd->TabIndex = 3;
			this->btnResetPwd->Text = L"忘记密码";
			this->btnResetPwd->UseVisualStyleBackColor = false;
			this->btnResetPwd->Click += gcnew System::EventHandler(this, &frmLogin::btnResetPwd_Click);
			// 
			// btnClear
			// 
			this->btnClear->Anchor = System::Windows::Forms::AnchorStyles::Top;
			this->btnClear->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(231)), static_cast<System::Int32>(static_cast<System::Byte>(76)), 
				static_cast<System::Int32>(static_cast<System::Byte>(60)));
			this->btnClear->FlatAppearance->BorderSize = 0;
			this->btnClear->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
			this->btnClear->Font = (gcnew System::Drawing::Font(L"微软雅黑", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->btnClear->ForeColor = System::Drawing::Color::White;
			this->btnClear->Location = System::Drawing::Point(488, 112);
			this->btnClear->Margin = System::Windows::Forms::Padding(6, 7, 6, 7);
			this->btnClear->Name = L"btnClear";
			this->btnClear->Size = System::Drawing::Size(59, 40);
			this->btnClear->TabIndex = 4;
			this->btnClear->Text = L"清空";
			this->btnClear->UseVisualStyleBackColor = false;
			this->btnClear->Click += gcnew System::EventHandler(this, &frmLogin::btnClear_Click);
			// 
			// txtBox1
			// 
			this->txtBox1->Anchor = System::Windows::Forms::AnchorStyles::Top;
			this->txtBox1->BackColor = System::Drawing::Color::White;
			this->txtBox1->Font = (gcnew System::Drawing::Font(L"微软雅黑", 15, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->txtBox1->ForeColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(64)), static_cast<System::Int32>(static_cast<System::Byte>(64)), 
				static_cast<System::Int32>(static_cast<System::Byte>(64)));
			this->txtBox1->Location = System::Drawing::Point(25, 43);
			this->txtBox1->Name = L"txtBox1";
			this->txtBox1->Size = System::Drawing::Size(313, 40);
			this->txtBox1->TabIndex = 5;
			this->txtBox1->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &frmLogin::txtBoxs_KeyDown);
			// 
			// txtBox2
			// 
			this->txtBox2->Anchor = System::Windows::Forms::AnchorStyles::Top;
			this->txtBox2->Font = (gcnew System::Drawing::Font(L"微软雅黑", 15, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->txtBox2->ForeColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(64)), static_cast<System::Int32>(static_cast<System::Byte>(64)), 
				static_cast<System::Int32>(static_cast<System::Byte>(64)));
			this->txtBox2->Location = System::Drawing::Point(25, 107);
			this->txtBox2->Name = L"txtBox2";
			this->txtBox2->PasswordChar = '*';
			this->txtBox2->Size = System::Drawing::Size(313, 40);
			this->txtBox2->TabIndex = 6;
			this->txtBox2->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &frmLogin::txtBoxs_KeyDown);
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(29, 1350);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(100, 27);
			this->textBox1->TabIndex = 7;
			// 
			// btnConfig
			// 
			this->btnConfig->Anchor = System::Windows::Forms::AnchorStyles::Top;
			this->btnConfig->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(127)), static_cast<System::Int32>(static_cast<System::Byte>(140)), 
				static_cast<System::Int32>(static_cast<System::Byte>(141)));
			this->btnConfig->FlatAppearance->BorderSize = 0;
			this->btnConfig->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
			this->btnConfig->Font = (gcnew System::Drawing::Font(L"微软雅黑", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->btnConfig->ForeColor = System::Drawing::Color::White;
			this->btnConfig->Location = System::Drawing::Point(347, 112);
			this->btnConfig->Margin = System::Windows::Forms::Padding(6, 7, 6, 7);
			this->btnConfig->Name = L"btnConfig";
			this->btnConfig->Size = System::Drawing::Size(54, 40);
			this->btnConfig->TabIndex = 8;
			this->btnConfig->Text = L"配置";
			this->btnConfig->UseVisualStyleBackColor = false;
			this->btnConfig->Click += gcnew System::EventHandler(this, &frmLogin::btnConfig_Click);
			// 
			// frmLogin
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(120, 120);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Dpi;
			this->BackColor = System::Drawing::SystemColors::Control;
			this->ClientSize = System::Drawing::Size(559, 180);
			this->Controls->Add(this->btnConfig);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->txtBox2);
			this->Controls->Add(this->txtBox1);
			this->Controls->Add(this->btnClear);
			this->Controls->Add(this->btnResetPwd);
			this->Controls->Add(this->btnLogin);
			this->Margin = System::Windows::Forms::Padding(6, 7, 6, 7);
			this->Name = L"frmLogin";
			this->ShowIcon = false;
			this->ShowInTaskbar = false;
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"";
			this->TopMost = true;
			this->TransparencyKey = System::Drawing::Color::Black;
			this->Load += gcnew System::EventHandler(this, &frmLogin::frmLogin_Load);
			this->Controls->SetChildIndex(this->btnLogin, 0);
			this->Controls->SetChildIndex(this->btnResetPwd, 0);
			this->Controls->SetChildIndex(this->btnClear, 0);
			this->Controls->SetChildIndex(this->txtBox1, 0);
			this->Controls->SetChildIndex(this->txtBox2, 0);
			this->Controls->SetChildIndex(this->textBox1, 0);
			this->Controls->SetChildIndex(this->btnConfig, 0);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
private: System::Void frmLogin_Load(System::Object^  sender, System::EventArgs^  e) {
		// this->BackColor=System::Drawing::Color::Green;
			//this->TransparencyKey=this->BackColor;
			 this->setBoarderColor(0x8e44ad);
			APIUtils::SetCueText(this->txtBox1,L"用户名");
			APIUtils::SetCueText(this->txtBox2,L"密码");
		}
private: System::Void btnLogin_Click(System::Object^  sender, System::EventArgs^  e);
private: System::Void btnClear_Click(System::Object^  sender, System::EventArgs^  e) {
			 txtBox1->Text="";
			 txtBox2->Text="";
		 }
private: System::Void btnResetPwd_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (btnLogin->Text=="登录")//
			 {
				 btnLogin->Text="重置密码";
				 txtBox2->Text="";
				 APIUtils::SetCueText(this->txtBox2,L"注册邮箱");
				 txtBox2->PasswordChar='\0';
				 btnResetPwd->Text="返回";
			 }else
			 {
				btnLogin->Text="登录";
				APIUtils::SetCueText(this->txtBox1,L"用户名");
				APIUtils::SetCueText(this->txtBox2,L"密码");
				txtBox2->PasswordChar='*';
				btnResetPwd->Text="忘记密码";
			 }
		 }
private: System::Void txtBoxs_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
			 if(e->KeyCode == Keys::Enter){
				 if(btnLogin->Enabled)
					btnLogin_Click(sender,e);
				 else
					 btnConfig_Click(sender,e);
			 }
		 }
private: System::Void btnConfig_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(btnConfig->Text=="配置"){
				APIUtils::SetCueText(this->txtBox1,L"服务器地址");
				APIUtils::SetCueText(this->txtBox2,L"服务器端口");
				txtBox2->PasswordChar='\0';
				txtBox1->Text="localhost";
				txtBox2->Text="8080";
				btnConfig->Text="确认";
				btnLogin->Enabled=false;
				btnResetPwd->Enabled=false;
			 }else{
				AsyncHttpUtils::server=txtBox1->Text;
				AsyncHttpUtils::port=txtBox2->Text;
				APIUtils::SetCueText(this->txtBox1,L"用户名");
				APIUtils::SetCueText(this->txtBox2,L"密码");
				txtBox2->PasswordChar='*';
				txtBox1->Text="";
				txtBox2->Text="";
				btnConfig->Text="配置";
				btnLogin->Enabled=true;
				btnResetPwd->Enabled=false;
			 }
		 }
}
;}
